package oneD.fem;

import inf.jlinalg.*;

public class Node {
	private int[] dofNumbers_ = new int[3];
	private Vector3D position_;
	private Constraint c_;
	private Force f_;
	private Vector3D displacement_;
	private int id;

	public Node(double x1, double x2, double x3) {
		this.position_ = new Vector3D(x1, x2, x3);
	}

	public void setId(int i) {
		this.id = i;
	}

	public int getId() {
		return this.id;
	}

	public void setConstraint(Constraint c) {
		this.c_ = c;
	}

	public Constraint getConstraint() {
		return this.c_;
	}

	public void setForce(Force f) {
		this.f_ = f;
	}

	public Force getForce() {
		return this.f_;
	}

	public Vector3D getForceVector() {
		if (this.f_ != null)
			return new Vector3D(this.f_.getComponent(0),
					this.f_.getComponent(1), this.f_.getComponent(2));
		else
			return new Vector3D(0.0, 0.0, 0.0);
	}

	public Vector3D getPosition() {
		return this.position_;
	}

	public void setDisplacement(double[] u) {
		this.displacement_ = new Vector3D(u);
	}

	public void updateDisplacement(double[] du) {
		this.displacement_ = this.displacement_.add(new Vector3D(du));
	}

	public Vector3D getDisplacement() {
		return this.displacement_;
	}

	public int enumerateDOFs(int start) {
		for (int i = 0; i < 3; i++)
			if (this.c_ != null)
				if (this.c_.isFree(i))
					this.dofNumbers_[i] = start++;
				else
					this.dofNumbers_[i] = -1;
			else
				this.dofNumbers_[i] = start++;
		return start;
	}

	public int[] getDOFNumbers() {
		return this.dofNumbers_;
	}

	public void printPosition() {
		System.out.print(MatrixFormat.format(this.position_));
	}

	public void printDisplacement() {
		System.out.print(MatrixFormat.format(this.displacement_));
	}

	public void printConstraint() {
		if (this.c_ == null)
			System.out.print("free\tfree\tfree");
		else
			this.c_.print();
	}

	public void printAll() {
		this.printPosition();
		this.printDisplacement();
	}

}
